
import axios from 'axios'
import { ElMessage } from 'element-plus'

const http=axios.create({
    baseURL:import.meta.env.VITE_APP_BASE_URL,
    timeout:3000
})

http.interceptors.request.use((config)=>{
    return config
},(error)=>{
    return Promise.reject(error)
})

//响应拦截器
http.interceptors.response.use((res)=>{
    const code=res.data.code
    const message=res.data.msg 
    if(code===500){
        ElMessage.error(message)
        return Promise.reject(message)
    }
    if(code===200){
        return res.data
    }
},error=>{
    return Promise.reject(error)
})

export default http